<?php


function pic_HTMLHead(){
	//echo '<html lang="en" xmlns:ng="http://angularjs.org"><head basepath=http://localhost/Repo/mypicsonline target=_blank> ';
	echo '<html lang="en" xmlns:ng="http://angularjs.org"><head > ';
	echo "<title>PicSharer </title>";
	pic_clientInclude();
//	echo '<base href="http://localhost/MyPicsOnline/svn" />';
	echo"</head>";
}

function pic_clientInclude(){
//TODO: Make sure all references are based on defined variable ABSPATH.

	addCSSToBrowser('./themes/base/jquery.ui.all.min.css',FALSE);
	addCSSToBrowser('./content/jqtheme/demos.css',FALSE);
	addCSSToBrowser('./content/css/myCss.css',FALSE);

	addJSToBrowser('./js/jquery-1.4.4.js',FALSE);
	addJSToBrowser('./content/js/myJs.js',FALSE);
	addJSToBrowser('./js/ui/jquery.ui.position.min.js',FALSE);
	addJSToBrowser('./js/ui/jquery.ui.core.min.js',FALSE);
	addJSToBrowser('./js/ui/jquery.ui.widget.min.js',FALSE);
	addJSToBrowser('./js/ui/jquery.ui.mouse.min.js',FALSE);
	addJSToBrowser('./js/ui/jquery.ui.draggable.min.js',FALSE);
	addJSToBrowser('./js/ui/jquery.ui.button.min.js',FALSE);
	addJSToBrowser('./js/ui/jquery.ui.tabs.min.js',FALSE);
	addJSToBrowser('./js/ui/jquery.ui.droppable.min.js',FALSE);
	addJSToBrowser('./js/ui/jquery.ui.resizable.min.js',FALSE);
	addJSToBrowser('./js/ui/jquery.ui.dialog.min.js',FALSE);
	addJSToBrowser('./js/ui/jquery.ui.selectable.min.js',FALSE);
	addJSToBrowser('./js/ui/jquery.ui.position.min.js',FALSE);

	echo '
	<script type="text/javascript" src="./content/js/angular-debug.js"></script>

	<script>
	$(function() {

				$( "#tabs" ).tabs({
					cache: true,
					ajaxOptions: {
						error: function( xhr, status, index, anchor ) {
							$( anchor.hash ).html(
								"Couldn\'t load this section. We\'ll try to fix this as soon as possible.");
						},
						success: function(){
	   						angular.compile(document.getElementById).$init();
	   						//alert();
	  					}
					},
					spinner: "Loading...<img src=\"./images/process.gif\" border=\"none\">"

				});
				});
	</script>
<style>
@font-face
{
	font-family: tabheaders;
	src: url(\'./content/css/fonts/RAVIE.TTF\')  format("truetype");
}

@font-face
{
	font-family: tabcontents;
	src: url(\'./content/css/fonts/HARNGTON.TTF\')  format("truetype");
}
</style>';
}

function addBrowserSpecificFile($file,$isBrowserSpecific=TRUE,$filePattern){

	$requestingsrc=($isBrowserSpecific == TRUE)?
	getBrowser():
	"Non-browserSpecific";

	switch ($requestingsrc)
	 {
	 	case "firefox":
	 	case "webkit": $file=str_replace($filePattern, "_".$requestingsrc.$filePattern, $file);
	 					break;
	 	//Ignore replacing .js as _other.js to file name.
	 	//If file is not browser specific add it as it is.
	 	case "other":
	 	default:
	 		break;
	 }
return $file;
}

function addJSTOBrowser($jsFile,$isBrowserSpecific=TRUE){
//Add browser specific java script file., Currently hardcoded to remove last 3 posotion .js and append with _browsername.js if browser specific is set to true
	echo '<script type="text/javascript" src="'.addBrowserSpecificFile($jsFile,$isBrowserSpecific,".js").'"> </script>';

}

function addCSSToBrowser($cssFile,$isBrowserSpecific=TRUE){
//Add browser specific CSS file. Currently hardcoded to remove last 4 posotion .css and append with _browsername.css
 	echo '<link rel="stylesheet" href="'.addBrowserSpecificFile($cssFile,$isBrowserSpecific,".css").'">';
}


function getBrowser(){
//Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.4) Gecko/20091016 Firefox/3.5.4
//Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.3 (KHTML, like Gecko) Chrome/6.0.472.25 Safari/534.3
//Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; AskTB5.6)
//TODO: Check for mobile and handheld devices and return appripriate browser names

	if( (substr_compare($_SERVER["HTTP_USER_AGENT"],"Firefox",stripos($_SERVER["HTTP_USER_AGENT"],"Firefox"),strlen("Firefox"),TRUE)) == 0 )	{
		return "firefox";
	}
	elseif (substr_compare($_SERVER["HTTP_USER_AGENT"],"AppleWebKit",stripos($_SERVER["HTTP_USER_AGENT"],"AppleWebKit"),strlen("AppleWebKit"),TRUE) == 0) {
		return "webkit";
	}
	else {
		return "other";
	}

}


function pic_loadModules(){
	addModules('./mod/peoplevoice/peoplevoice.php',"homeModule");
	addModules('./mod/peoplevoice/peoplevoice.php',"homeModule1","srcGalleryView","right top","right top","1 1","style=\"width:15em;\"");
	//"background='red'"
}

function addModules($modPath,$divid,$targetelement="container",$myalign="right top",$targetalign="right top",$offset="1 125",$extraProps=null){
//	echo '<div class="mod" name="'.$divid.'" id="'.$divid.'" ';
//	echo ' onMouseover=\' $( ".mod" ).position({of: $("#container"),	my:"'.$myalign.'",at: "'.$targetalign.'",offset: "'.$offset.'"});alert("sd");\'';
//	echo "$extraProps>";
//	echo file_get_contents($modPath) ."</div>";

	echo '<iframe src="'.$modPath.'" id="'.$divid.'" class="mod"';
	echo ' onMouseover=\' $( "#'.$divid.'" ).position({of: $("#'.$targetelement.'"),	my:"'.$myalign.'",at: "'.$targetalign.'",offset: "'.$offset.'"});\'';
	echo "$extraProps></iframe>";


}

?>